/* 
 * JavaScript functions for iPublish application
 * @author: Csatlos Sandor <csatlos.sandor@gmail.com>
 * @date: 2010-11-04
 */


$(document).ready(function()
{
    
    //Validate edition form
    //$("#formEdition").submit(function()
    $("#save_images").click(function()
    {       
	var errorMsg = "";
        //Title
       /* if ( $('#title').val() == '' )
        {
            $('#title').css('border-color', 'red');
            errorMsg += "Edition title is mandatory<br>";
        }
        else
            $('#title').css('border-color', '#B4B4B4');
*/
        //Front Cover
		
		
        if ( $('#txtContent_Image1').val() == '')
        {			
            $('#txtContent_Image1').css('border-color', 'red');
            errorMsg += "First image is mandatory<br>";
        }
        else
		{
			var array = $('#txtContent_Image1').val().split('.');
			var extension= array[1].toUpperCase();
			if (( extension!='JPG') && (extension!='PNG')&& (extension!='JPEG'))
			{	
				$('#txtContent_Image1').css('border-color', 'red');
				errorMsg += "First image must be JPG/PNG<br>";
			}
			else
            $('#txtContent_Image1').css('border-color', '#B4B4B4');
		}
		
       if ( $('#txtContent_Image2').val() == ''  )
        {
			
            $('#txtContent_Image2').css('border-color', 'red');
            errorMsg += "Second image is mandatory<br>";
        }
        else
		{	
			var array = $('#txtContent_Image2').val().split('.');
			var extension= array[1].toUpperCase();
			if ( extension!='JPG' && extension!='PNG'&& extension!='JPEG')
			{
				$('#txtContent_Image2').css('border-color', 'red');
				errorMsg += "Second image must be JPG/PNG<br>";
			}
			else
            $('#txtContent_Image2').css('border-color', '#B4B4B4');
		}

		
        if ( errorMsg != '' )
        {
            $('#edition_error').html(errorMsg);
        }
        else
        {
            $('#edition_error').html("");
            if ( $('#txtContent_Image1').val() != '')
            {
                $('#txtContent_Image1').hide();
                $('#first_img_loading').show();
            }
            if ( $('#txtContent_Image2').val() != '')
            {
                $('#txtContent_Image2').hide();
                $('#second_img_loading').show();
            }
            $("#formSplashImage").submit();

        }
        return false;
    });
    /*$("#upload_target").load(function()
    {
        var doc =document.getElementById('upload_target').contentWindow.document
        var result = doc.body.innerHTML;

        location.href='index.php?eid='+result;
    });

    $("#editions").change(function()
    {
        if ($("#editions").val() == '' )
            location.href='index.php';
        else
            location.href='index.php?eid='+$("#editions").val();
    });

    $("#delete_edition").click(function()
    {
        if (confirm('This action will remove this record from our database permenantly.  Are you sure you want to do this?'))
            location.href = 'delete_edition.php?eid='+$("#editions").val();
    })*/

});

